/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.common.c;

import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.common.i.c;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.zip.GZIPInputStream;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.util.ByteArrayBuffer;

public class b {
    private static String a = "HttpHelper";

    public static byte[] a(InputStream paramInputStream) {
        c.a(a, new Object[] { "stream2String is = ", (paramInputStream == null) ? "null" : "yes" });
        if (paramInputStream == null)
            return null;
        int i = 0;
        byte[] arrayOfByte = new byte[1024];
        ByteArrayBuffer localByteArrayBuffer = new ByteArrayBuffer(0);
        while ((i = paramInputStream.read(arrayOfByte)) > 0)
            localByteArrayBuffer.append(arrayOfByte, 0, i);
        return localByteArrayBuffer.toByteArray();
    }

    public static String b(InputStream paramInputStream) {
        return a(paramInputStream, "UTF-8");
    }

    public static String a(InputStream paramInputStream, String paramString) {
        byte[] arrayOfByte = a(paramInputStream);
        c.a(a,
                new Object[] { "stream2String bytes's length = ",
                        Integer.valueOf((arrayOfByte == null) ? 0 : arrayOfByte.length) });
        if (TextUtils.isEmpty(paramString))
            paramString = "UTF-8";
        if (arrayOfByte != null)
            return new String(arrayOfByte, paramString);
        return null;
    }

    public static String a(String paramString) {
        c.a(a, new Object[] { "encodeUrl = ", paramString });
        if (TextUtils.isEmpty(paramString))
            return null;
        paramString = paramString.replaceAll(" ", "%20");
        StringBuilder localStringBuilder = new StringBuilder();
        for (int i = 0; i < paramString.length(); ++i) {
            char c = paramString.charAt(i);
            byte[] arrayOfByte = String.valueOf(c).getBytes();
            if ((arrayOfByte == null) || (arrayOfByte.length <= 0))
                throw new UnsupportedEncodingException();
            if (arrayOfByte.length == 1) {
                localStringBuilder.append(c);
            }
            else {
                String str = new String(arrayOfByte);
                str = URLEncoder.encode(str, "UTF-8");
                localStringBuilder.append(str);
            }
        }
        return localStringBuilder.toString();
    }

    public static String[] a(HttpResponse paramHttpResponse) {
        String[] arrayOfString = null;
        Header[] arrayOfHeader = paramHttpResponse.getHeaders("set-cookie");
        if (arrayOfHeader != null) {
            String str = null;
            int i = arrayOfHeader.length;
            arrayOfString = new String[i];
            for (int j = 0; j < i; ++j) {
                str = arrayOfHeader[j].getValue();
                if (TextUtils.isEmpty(str))
                    continue;
                arrayOfString[j] = str;
                c.a(a, new Object[] { "getHttpCookie, cookie = ", str });
            }
        }
        return arrayOfString;
    }

    public static InputStream a(HttpEntity paramHttpEntity) {
        Object localObject = null;
        if (paramHttpEntity != null) {
            localObject = paramHttpEntity.getContent();
            Header localHeader = paramHttpEntity.getContentEncoding();
            if (localHeader != null) {
                String str = localHeader.getValue();
                c.a(a, new Object[] { "Content Encoding = ", str });
                if ((!(TextUtils.isEmpty(str))) && (str.contains("gzip")))
                    localObject = new GZIPInputStream((InputStream) localObject);
            }
        }
        return ((InputStream) localObject);
    }
}